package com.tuozixuan.jmh.demo;

import java.util.concurrent.TimeUnit;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Measurement(iterations = 3, time = 100, timeUnit = TimeUnit.MILLISECONDS, batchSize = 100)
@Warmup(iterations = 3, time = 100, timeUnit = TimeUnit.MILLISECONDS)
public class JmhDemo_Measurement {

	@Benchmark
	@BenchmarkMode(Mode.AverageTime)
	public void measureAvgTime() {
		concat();
	}
	
	private String concat() {
		String a = "select id, name from user";
		String c = "";
		for (int i = 0; i < 100; i++) {
			c += a;
		}
		return c;
	}

	public static void main(String[] args) throws RunnerException {
        Options opt = new OptionsBuilder()
                .include(JmhDemo_Measurement.class.getSimpleName())
                .forks(1)
                .build();
        new Runner(opt).run();
    }
}
